import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:safetymonitor/app/components/custom_app_bar.dart';
import 'package:safetymonitor/app/core/core.dart';
import 'package:safetymonitor/modules/home/home_page/duty_manager/duty/view.dart';
import 'package:safetymonitor/modules/home/home_page/duty_manager/duty_record/view.dart';
import 'package:safetymonitor/router/app_pages.dart';

import 'duty_manager_controller.dart';




/// 值班记录
final class DutyManagerPage extends StatefulWidget {
  const DutyManagerPage({super.key});

  @override
  State<DutyManagerPage> createState() => _DutyManagerPageState();
}
///值班管理
class _DutyManagerPageState  extends State<DutyManagerPage> with AutomaticKeepAliveClientMixin {

  final controller = Get.put(DutyManagerController());
  @override
  bool get wantKeepAlive => true;
  @override
  Widget build(BuildContext context) {
    super.build(context);
    return Scaffold(
      appBar: CustomAppBar(
        title: Text(
          '值班管理',
          style: TextStyle(fontSize: 16.w),
        ),
        actions: [
          Obx(() {
            return Visibility(
              visible: controller.isShow.value,
              child: IconButton(
                onPressed: () {
                  Get.toNamed(Routes.startSchedulingPage)?.then((_) {
                    //刷新数据
                  });
                },
                icon: Container(
                  padding: EdgeInsets.only(
                    left: 8.w,
                    right: 8.w,
                    top: 3,
                    bottom: 3.w,
                  ),
                  decoration: BoxDecoration(
                    color: Colors.blue,
                    borderRadius: BorderRadius.all(
                      Radius.circular(6.r),
                    ),
                  ),
                  child: const Text(
                    '排班',
                    style: TextStyle(color: Colors.white),
                  ),
                ),
              ),
            );
          }),
        ],
        backgroundColor: Colors.white,
        centerTitle: true,
      ),
      body: Container(
        color: AppColors.bg_color_grey,
        child: Column(
          children: [
            Container(
              padding: EdgeInsets.symmetric(horizontal: 30.w),
              decoration: BoxDecoration(
                color: Colors.white,
                borderRadius: BorderRadius.circular(8),
              ),
              height: 54.w,
              child: TabBar(
                controller: controller.tabController,
                enableFeedback: false,
                tabs: const [
                  Tab(text: '值班记录'),
                  Tab(text: '排班'),
                ],
                dividerColor: Colors.transparent,
                labelPadding: EdgeInsets.only(bottom: 10.w),
                labelStyle: TextStyle(
                  fontSize: 16.sp,
                  fontWeight: FontWeight.w500,
                ),
                unselectedLabelStyle: TextStyle(
                  fontSize: 16.sp,
                  fontWeight: FontWeight.w500,
                ),
                labelColor: Colors.black,
                unselectedLabelColor: const Color(0xffA0A7B5),
                indicatorPadding: EdgeInsets.only(top: 36.w, bottom: 10.w),
                indicator: const BoxDecoration(
                  image: DecorationImage(
                    image: AssetImage(
                      'assets/images/icon_select_arc.png',
                    ),
                  ),
                ),
              ),
            ),
            Expanded(
              child: Container(
                color: const Color(0xffF5F5F6),
                child: TabBarView(
                  controller: controller.tabController,
                  children: [
                    const DutyRecordPage(),
                    DutyMgmtPage(),
                  ],
                ),
              ),
            ),
          ],
        ),
      ),
    );
  }
}
